﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Com.Charence.PassManager.Common;
using Com.Charence.PassManager.DataComponents;

namespace Com.Charence.PassManager.BusinessComponents
{
    public class AuthenticateBC
    {
        private readonly AuthenticateDC _authDC = new AuthenticateDC();

        public void AddQRToken(string tokenString)
        {
            _authDC.AddQRToken(tokenString);
        }

        public bool ConnentHub(string tokenString, string connectionId)
        {
            return _authDC.ConnentHub(tokenString, connectionId);
        }

        public string TryQRLogin(string tokenString, string userName, Passcode password, out string errMsg)
        {
            try
            {
                errMsg = string.Empty;
                return _authDC.TryQRLogin(tokenString, userName, password.ToString());
            }
            catch (LoginException ex)
            {
                errMsg = ex.Message;
                return null;
            }
        }

        public int DoLogin(string tokenString, out string message)
        {
            return _authDC.DoLogin(tokenString, out message);
        }

        public int DoLoginOnWeb(string userName, Passcode password, out string errMsg)
        {
            try
            {
                errMsg = string.Empty;
                return _authDC.DoLoginOnWeb(userName, password.ToString());
            }
            catch (LoginException ex)
            {
                errMsg = ex.Message;
                return 0;
            }
        }
    }
}
